package backstage.app.service.impl.util;

import java.time.LocalDateTime;
 

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import backstage.app.entity.Constitution;
import backstage.app.mapper.ConstitutionMapper;
import backstage.app.respont.RespontDateJson;

 
@Component
public class ConstitutionImplUtil {

	@Autowired
	private ConstitutionMapper constitutionMapper;
	
	 private static final Logger logger = (Logger) LoggerFactory.getLogger(ConstitutionImplUtil.class);
	
	public RespontDateJson<?>insert(
			Integer sid,
			//学生对应id
			Integer conditionType,double height,
			double width,double abduction,double fingerSpan,
			//大文本
			double singForward,
			Integer roundTrip,double courtSprint,double restrtedArea,
			double klingWing,Integer verticalJump,Integer continJump,
			//备注
		String remake){
		
		Constitution constitution=new Constitution();
		constitution.setSid(sid);
		constitution.setHeight(height);
		//对应
		constitution.setCpId(conditionType);
		constitution.setWeight(width);
		constitution.setAbduction(abduction);
		constitution.setFingerSpan(fingerSpan);
		constitution.setSingForward(singForward);
		constitution.setRoundTrip(roundTrip);
		constitution.setCourtSprint(courtSprint);
		constitution.setRestrtedArea(restrtedArea);
		constitution.setKlingWing(klingWing);
		constitution.setVerticalJump(verticalJump);
		constitution.setContiNump(continJump);
		constitution.setRemake(remake);
		constitution.setCreateTime(LocalDateTime.now());
		constitution.setGenerateTime(LocalDateTime.now());
		constitution.setUpdateTime(LocalDateTime.now());
		int result=-1;
		try {
			  result=constitutionMapper.insert(constitution);
			  return result>0?RespontDateJson.ok(result, "添加成功"):RespontDateJson.fuall(result,"添加失败，出现未知异常，请联系开发人员");
		} catch (Exception e) {
			logger.error("学员添加体质测试时，数据库发生异常！");
			return RespontDateJson.fuall(result, "学员添加体质测试时，数据库发生异常！");
		}
		 
		
		 
	}
	
	
	
	
	//3-6 岁幼儿测试
	public Constitution getConstitution1(Constitution constitution) {
		
		//身高
		if(constitution.getHeight()<=36) {
			constitution.setHeightRemake("仍需努力");
		}else if(constitution.getHeight()>36&&constitution.getHeight()<=72) {
			constitution.setHeightRemake("合格");
		}else if(constitution.getHeight()>72&&constitution.getHeight()<=108) {
			constitution.setHeightRemake("良好");
		}else if(constitution.getHeight()>108&&constitution.getHeight()<=144||constitution.getHeight()>144) {
			constitution.setHeightRemake("优秀");
		}
		
		
		 
	 
		 //体重
		if(constitution.getWeight()<=10) {
			constitution.setWeightRemake("偏瘦");
		}else if(constitution.getWeight()>10 && constitution.getWeight()<=15) {
			constitution.setWeightRemake("正常");
		}else if(constitution.getWeight()>15 && constitution.getWeight()<=20) {
			constitution.setWeightRemake("偏肥");
		}else if(constitution.getWeight()>20 && constitution.getWeight()<=25||constitution.getWeight()>25) {
			constitution.setWeightRemake("肥胖");
		} 
		
		
		//坐位体前屈
	 
		 
		if(constitution.getAbduction()<=4) {
				constitution.setAbductionRemake("仍需努力");
		}else if(constitution.getAbduction()>4&& constitution.getAbduction()<=8) {
			constitution.setAbductionRemake("合格");
		}else if(constitution.getAbduction()>8&& constitution.getAbduction()<=12||constitution.getAbduction()>12) {
			constitution.setAbductionRemake("良好");
		} 
			
		
		//立定跳远
		 
		if(constitution.getSingForward()<=24) {
			constitution.setSingForwardRemake("仍需努力");
		}else if(constitution.getSingForward()>24&&constitution.getSingForward()<=48) {
			constitution.setSingForwardRemake("合格");
		}else if(constitution.getSingForward()>48&&constitution.getSingForward()<=72) {
			constitution.setSingForwardRemake("良好");
		}else if(constitution.getSingForward()>72&&constitution.getSingForward()<=96||constitution.getSingForward()>96) {
			constitution.setSingForwardRemake("优秀");
		}
		 
		
		//双脚连续跳
	 
		if(constitution.getFingerSpan()==1) {
			constitution.setFingerSpanRemake("仍需努力");
		}else if(constitution.getFingerSpan()==2) {
			constitution.setFingerSpanRemake("合格");
		}else if(constitution.getFingerSpan()==3) {
			constitution.setFingerSpanRemake("良好");
		}else  if(constitution.getFingerSpan()==4||constitution.getFingerSpan()>4){
			constitution.setFingerSpanRemake("优秀");
		}
		 	
		
		//10 米折返跑
		if(constitution.getRoundTrip()<=2.5) {
			constitution.setRoundTripRemake("仍需努力");
		}else if(constitution.getRoundTrip()>2.5&&constitution.getRoundTrip()<=4.5) {
			constitution.setRoundTripRemake("合格");
		}else if(constitution.getRoundTrip()>4.5&&constitution.getRoundTrip()<=7.5) {
			constitution.setRoundTripRemake("良好");
		}else if(constitution.getRoundTrip()>7.5&&constitution.getRoundTrip()<=9.5||constitution.getRoundTrip()>9.5) {
			constitution.setRoundTripRemake("优秀");
		}
		 	
		
		//网球掷远 
		if(constitution.getCourtSprint() <1.5) {
			constitution.setCourtSprintRemake("仍需努力");
		}else if(constitution.getCourtSprint()>1.5&&constitution.getCourtSprint()<=4.5) {
			constitution.setCourtSprintRemake("合格");
		}else if(constitution.getCourtSprint()>4.5&&constitution.getCourtSprint()<=8.5) {
			constitution.setCourtSprintRemake("良好");
		}else if(constitution.getCourtSprint()>8.5&&constitution.getCourtSprint()<=11.5||constitution.getCourtSprint()>11.5) {
			constitution.setCourtSprintRemake("优秀");
		} 
			
		//走平衡木
		if(constitution.getRestrtedArea()<=2) {
			constitution.setRestrtedAreaRemake("仍需努力");
		}else if(constitution.getRestrtedArea()>2&& constitution.getRestrtedArea()<=4) {
			constitution.setRestrtedAreaRemake("合格");
		}else if(constitution.getRestrtedArea()>4&& constitution.getRestrtedArea()<=6) {
			constitution.setRestrtedAreaRemake("良好");
		}else if(constitution.getRestrtedArea()>6&& constitution.getRestrtedArea()<=8||constitution.getRestrtedArea()>8) {
			constitution.setRestrtedAreaRemake("优秀");
		}
	 
		return constitution;
	}
	
	
	
	
	
	
}
